#-*-coding:utf-8-*-
__author__ = 'toriycn'

from rediscluster import StrictRedisCluster
import redis
class RedisHelper:

    def __init__(self,host,port,chan_sub,chan_pub):
        #startup_nodes = [{"host": host, "port": port}]
        #self.rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
        self.rc = redis.Redis(host= host,port = port)
        self.chan_sub = chan_sub
        self.chan_pub = chan_pub

    def get(self,key):
        return self.rc.get(key)

    def set(self,key,value):
        self.rc.set(key,value)

    def keys(self,pattern="*"):
        return self.rc.keys(pattern)

    def delete(self,key):
        return self.rc.delete(key)


    def public(self,msg):
        self.rc.publish(self.chan_pub,msg)
        return True

    def subscribe(self):
        pub = self.rc.pubsub()
        pub.subscribe(self.chan_sub)
        pub.parse_response()
        return pub


if __name__ == '__main__':
    r = RedisHelper("127.0.0.1",6379,"dl","dl")
    r.rc.zadd("myset",13810094207,1000)
    r.rc.zadd("myset",13810094208,2000)
    r.rc.zadd("myset",18600020686,3000)
    r.rc.zadd("myset",18600020687,2000)
    print(r.rc.zrange("myset",0,-1,True,True,int))
    print(r.rc.zscore("myset","18600020686"))
    r.rc.delete("myset")
